package app.com.mysnackbardemo;

import android.graphics.Color;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    FloatingActionButton floatingActionButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        floatingActionButton = (FloatingActionButton) findViewById(R.id.flb_black);
        CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);
        floatingActionButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Snackbar.make(v,"这是massage", Snackbar.LENGTH_LONG).show();
            }
        });
    }

    public void click(View view) {
       /* Snackbar.make(view,"这是massage", Snackbar.LENGTH_LONG).
                setAction("这是action", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this,"你点击了action",Toast.LENGTH_SHORT).show();
            }
        }).show();*/
//        Snackbar.make(view,"这是massage", Snackbar.LENGTH_LONG).show();

        Snackbar snackbar = Snackbar.make(view,"Hello Snackbar",Snackbar.LENGTH_LONG);

        //click的字体颜色
        snackbar.setActionTextColor(Color.RED);
//        设置Snackbar的背景颜色
        View mView = snackbar.getView();
        mView.setBackgroundColor(Color.BLUE);
//内容的字体颜色与大小
        TextView tvSnackbarText = (TextView) mView.findViewById(android.support.design.R.id.snackbar_text);
        tvSnackbarText.setText("hello world");
        tvSnackbarText.setTextColor(Color.RED);
        tvSnackbarText.setTextSize(30);

//设置按钮，名字为click
        snackbar.setAction("click", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getBaseContext(),"action clicked",Toast.LENGTH_SHORT).show();
            }
        }).show();


   /*     SnackbarUtil.ShortSnackbar(view,"妹子向你发来一条消息",SnackbarUtil.Info).show();
        Snackbar snackbar= SnackbarUtil.ShortSnackbar(coordinator,"妹子删了你发出的消息",SnackbarUtil.Warning).setActionTextColor(Color.RED).setAction("再次发送", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SnackbarUtil.LongSnackbar(coordinator,"妹子已将你拉黑",SnackbarUtil.Alert).setActionTextColor(Color.WHITE).show();
            }
        });

        SnackbarUtil.SnackbarAddView(snackbar,R.layout.snackbar_addview,0);

        SnackbarUtil.SnackbarAddView(snackbar,R.layout.snackbar_addview2,2);

        snackbar.show();*/

      /*  作者：简名
        链接：http://www.jianshu.com/p/cd1e80e64311
        來源：简书
        著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。*/
    }

    public static void setSnackbarColor(Snackbar snackbar, int messageColor, int backgroundColor) {
        View view = snackbar.getView();//获取Snackbar的view
        if(view!=null){
            view.setBackgroundColor(backgroundColor);//修改view的背景色
            ((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(messageColor);//获取Snackbar的message控件，修改字体颜色
        }
    }
}
